<?php

namespace App\Http\Controllers\Admin;

use App\Models\Index\LiveMovieCate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LiveMovieCateController extends Controller
{
    public function getMovieCateList(Request $request)
    {
        $data = LiveMovieCate::getCateListPaginate();
        return self::response($data,200);
    }

    /**
     * 新增/修改 配置
     * @param Request $request
     * @return mixed
     */
    public function modifyMovieCate(Request $request)
    {
        $input = $request->all();

        if (empty($input['cate_name'])){
            return self::response(null,'-1','cate_name is null');
        }

        if (empty($input['cate_img'])){
            return self::response(null,'-1','cate_img is null');
        }
        if (!preg_match('/^(0|\+?[1-9][0-9]*)$/',$input['sort'])){
            return self::response(null,'-1','sort is null');
        }

        if (empty($input['attribute'])){
            return self::response(null,'-1','attribute is null');
        }
        $input = Controller::createData('live_movie_cate',$input);
        if (empty($input['cate_id'])){
            unset($input['cate_id']);
            $flag = LiveMovieCate::query()->insert($input);
            $msg  = '新增';
        }else{
            $flag = LiveMovieCate::query()->where('cate_id',$input['cate_id'])->update($input);
            $msg  = '修改';
        }
        if ($flag){
            return self::response(null,200,$msg.'成功');
        }else{
            return self::response(null,-1,$msg.'失败');
        }
    }


    public function del(Request $request)
    {
        $input = $request->all();
        if (empty($input['cate_id'])){
            return self::response(null,'-1','请选择删除项');
        }
        $flag = LiveMovieCate::query()->where('cate_id',$input['cate_id'])->delete();
        if ($flag){
            return self::response(null,200,'删除成功');
        }else{
            return self::response(null,-1,'删除失败');
        }
    }
}
